#include <bits/stdc++.h>
using namespace std;
int num[1000010];
int main() {
  int n, m;

  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int l, r;
    cin >> l >> r;
    for (int j = l; j <= r; j++) {
      num[j]++;
    }
  }
  cout << *min_element(num + 1, num + n + 1) << endl; // 输出最小值

  return 0;
}